package com.tom.happy.mrs.chicken;

import android.app.Application;

import com.baidu.mobads.AdView;
import com.orhanobut.logger.LogLevel;
import com.orhanobut.logger.Logger;
import com.tom.happy.mrs.chicken.service.MyPushIntentService;
import com.tom.happy.mrs.chicken.utils.PrefUtils;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.message.IUmengRegisterCallback;
import com.umeng.message.PushAgent;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        Logger.init("xiaoji").setLogLevel(LogLevel.FULL);
        initUMengPush();
        String appId = PrefUtils.getAppID(this);
        AdView.setAppSid(this, appId);
    }

    private void initUMengPush() {
        //初始化组件化基础库, 统计SDK/推送SDK/分享SDK都必须调用此初始化接口
        UMConfigure.init(this, "58eb6dfb99f0c74f0a00111a", "Umeng",
                UMConfigure.DEVICE_TYPE_PHONE,"ea118bf6bb335f7febe71a82f5a89255");
        // 友盟推送
        PushAgent mPushAgent = PushAgent.getInstance(this);
        //注册推送服务，每次调用register方法都会回调该接口
        mPushAgent.register(new IUmengRegisterCallback() {

            @Override
            public void onSuccess(String deviceToken) {
                //注册成功会返回device token
                Logger.e("token: " + deviceToken);
            }

            @Override
            public void onFailure(String s, String s1) {
                Logger.e("register token error: " + s + "....: " + s1);
            }
        });

        mPushAgent.setPushIntentServiceClass(MyPushIntentService.class);
    }
}
